/******************************************************************************************************
Copyright (C) 2019 Mestrelab Research S.L. All rights reserved.

This file is part of the Mnova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/
/*globals Application, StandardItemModel */
/*jslint plusplus: true, continue: true, bitwise: true*/

function treeViewTest() {

	"use strict";

	/* load the UI (it should contain a widget of type TreeView called treeView) */
	var treeViewDialog = Application.loadUiFile("ricares:treeViewTest.ui");

	/* create a new StandardItemModel object */
	var mySim = new StandardItemModel();

	/* define the main (0 and 1) branches and their children */
	var myObject000 = {text: "I am 000", flags: 33, children: []};
	var myObject00 = {text: "I am 00", flags: 33, children: [myObject000]};
	var myObject01 = {text: "I am 01", flags: 33, children: []};
	var myObject0 = {text: "I am 0", flags: 33, children: [myObject00, myObject01]};
	var myObject1 = {text: "I am 1", flags: 33, children: []};

	/* populate the StandardItemModel */
	mySim.items = [myObject0, myObject1];

	/* get the info from the StandardItemModel */
	var myItems = mySim.items;

	/* overwrite the information of branch 0 (it will not overwrite its children) */
	myItems[0].text = "I am 0 (overwritten)";

	/* populate the StandardItemModel again with the updated info */
	mySim.items = myItems;

	/* define the header of the StandardItemModel */
	mySim.header = "This is my tree";

	/* load the model into the TreeView */
	treeViewDialog.widgets.treeView.setModel(mySim);
}